package com.yanqu.road.server.cmd.activity.soulbone;

import com.yanqu.road.entity.activity.soulbone.SoulBoneConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SoulBoneProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.soulbone.SoulBoneModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.SoulBoneActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = SoulBoneProto.SoulBoneDrawReqMsg.class, respMsg = SoulBoneProto.SoulBoneDrawRespMsg.class)
@Cmd(code = Protocol.S_SOUL_BONE_DRAW, desc = "转盘")
public class SoulBoneDrawCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SoulBoneConfig config = SoulBoneActivityMgr.getConfig();
        // 没有活动
        if (config == null || !ActivityMgr.activityInTimeAndShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        SoulBoneProto.SoulBoneDrawReqMsg req = SoulBoneProto.SoulBoneDrawReqMsg.parseFrom(packet.getBytes());
        if(req.getType() != 1 && req.getType() != 2){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }

        ret = player.getModule(SoulBoneModule.class).draw(req.getType());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_SOUL_BONE_DRAW, SoulBoneProto.SoulBoneDrawRespMsg.newBuilder().setRet(ret));
        }
    }
}
